package com.indusfo.spc.controller;

import com.indusfo.spc.aspect.SystemControllerLog;
import com.indusfo.spc.pojo.Pro;
import com.indusfo.spc.pojo.Repair;
import com.indusfo.spc.service.RepairService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 维修线下信息控制层
 */
@Controller
@RequestMapping("/service/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

    /**
     * 修改维修线下信息
     *
     * @param repair
     * @return
     */
    @RequestMapping(value = "/updateRepair", method = RequestMethod.POST)
    @SystemControllerLog(description = "修改维修线下信息")
    @ResponseBody
    public JSONObject updateRepair(@RequestBody Repair repair) {

        JSONObject json = repairService.updateRepair(repair);
        return json;
    }

    /**
     * 查询维修线下信息
     *
     * @param repair
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value = "/queryRepair")
    @SystemControllerLog(description = "查询维修线下信息")
    @ResponseBody
    public JSONObject queryRepair(Repair repair) {

        JSONObject json = repairService.selectAll(repair);
        return json;
    }

    /**
     * 插入维修线下信息
     *
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value = "/insertRepair", method = RequestMethod.POST)
    @SystemControllerLog(description = "新增维修线下信息")
    @ResponseBody
    public JSONObject insertRepair(Repair repair) {

        JSONObject json = repairService.insertRepair(repair);
        return json;
    }

    /**
     * 启用/停用 维修线下信息
     *
     * @param repairIds, dataState
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value = "/definesRepair", method = RequestMethod.POST)
    @SystemControllerLog(description = "启用/停用维修线下信息")
    @ResponseBody
    public JSONObject definesRepair(Long[] repairIds, Integer dataState) {

        JSONObject json = repairService.deleteRepair(repairIds, dataState);
        return json;
    }

    /**
     * 删除维修线下信息
     *
     * @param repairIds, dataState
     * @return com.indusfo.spc.vo.JSONObject
     */
    @RequestMapping(value = "/deleteRepair", method = RequestMethod.POST)
    @SystemControllerLog(description = "删除维修线下信息")
    @ResponseBody
    public JSONObject deleteRepair(Long[] repairIds, Integer dataState) {

        dataState = 2;
        JSONObject json = repairService.deleteRepair(repairIds, dataState);
        return json;
    }

    /**
     * 去添加查询（产品，任务单，批次）
     */
    @RequestMapping(value = "/queryListRepairToInsert")
    @ResponseBody
    public JSONObject queryListRepairToInsert(Repair repair) {
        JSONObject json = repairService.queryListRepairToInsert(repair);
        return json;
    }
}
